package tests;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class ApplicationTest implements Observer {

	private JFrame frame;
	JLabel resultat;
	JButton bouton;
	Requete requete;
	
	public JButton getBouton() {
		return bouton;
	};

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Requete requete = new Requete();
					ApplicationTest window = new ApplicationTest(requete);
					TestControleur controleur = new TestControleur(requete, window);
					window.getBouton().addActionListener(controleur);
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public ApplicationTest(Requete requete) {
		initialize();
		this.requete = requete;
		requete.addObserver(this);
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(new BorderLayout(0, 0));
		
		JPanel panel = new JPanel();
		frame.getContentPane().add(panel, BorderLayout.NORTH);
		panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		bouton = new JButton("Ex\u00E9cuter la requ\u00EAte");
		panel.add(bouton);
		
		JPanel panel_1 = new JPanel();
		frame.getContentPane().add(panel_1, BorderLayout.CENTER);
		
		resultat = new JLabel("R\u00E9sultat de la requ\u00EAte");
		panel_1.add(resultat);

	}

	@Override
	public void update(Observable o, Object arg) {
		this.resultat.setText(requete.getTexte());
		
	}

}
